<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="设备名称">
              <me-dict-select-tag v-model="queryParam.ppjzsbId" dictCode="ppgy_ppjzsb,sbmc,id" placeholder="请选择设备名称" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search" >查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('ppgy_jzzd')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="ppjzsbId"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">

          <a @click="handleInfo(record)">加注控制</a>
          <a-divider type="vertical" />
          <a @click="handleHistory(record)">制度历史记录</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.ppjzsbId)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ppgy-jzzd-modal ref="modalForm" @ok="modalFormOk"></ppgy-jzzd-modal>

    <a-modal
      title="执行制度"
      :width="800"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      ok-text="执行"
      cancel-text="取消"
    >
      <a-spin :spinning="false">
        <fieldset>
          <a-form-model ref="form1" :model="model1" :rules="validatorRules1">
            <a-row>
              <a-col :span="12">
                <a-form-model-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillingEquipmentId">
                  <!-- <a-input v-model="model.fillingEquipmentId" placeholder="请输入设备编号"  ></a-input> -->
                  <!-- <j-dict-select-tag v-model="model1.ppjzsbId" :disabled="true" dictCode="znjz_filling_equipment,equipment_name,id" placeholder="请选择设备" ></j-dict-select-tag> -->
                  <me-dict-select-tag type="list" :disabled="true" v-model="model1.ppjzsbId" dictCode="ppgy_ppjzsb,sbmc,id" placeholder="请选择设备名称" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item label="加注时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jzsj">
                  <a-input-number v-model="model1.jzsj" :disabled="true" placeholder="请输入加注时间" style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                 <a-form-model-item label="循环加注的循环时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xhsj">
                  <a-input-number v-model="model1.xhsj" :disabled="true" placeholder="请输入循环加注的循环时间" style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item label="药剂配置比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yjpzbl">
                  <a-input-number :disabled="true" v-model="model1.yjpzbl" placeholder="请输入药剂配置比例" style="width: 100%" />
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </fieldset>
      </a-spin>
    </a-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import PpgyJzzdModal from './modules/PpgyJzzdModal'
  import { httpAction } from '@/api/manage'

  export default {
    name: 'PpgyJzzdList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      PpgyJzzdModal
    },
    data () {
      return {
        description: 'ppgy_jzzd管理页面',
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          // },
          {
            title:'设备名称',
            align:"center",
            dataIndex: 'ppjzsbId_dictText'
          },
          {
            title:'加注时间',
            align:"center",
            dataIndex: 'jzsj'
          },
          {
            title:'循环加注的循环时间',
            align:"center",
            dataIndex: 'xhsj'
          },
          {
            title:'药剂配置比例',
            align:"center",
            dataIndex: 'yjpzbl'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ppgyJzzd/ppgyJzzd/list",
          delete: "/ppgyJzzd/ppgyJzzd/delete",
          deleteBatch: "/ppgyJzzd/ppgyJzzd/deleteBatch",
          exportXlsUrl: "/ppgyJzzd/ppgyJzzd/exportXls",
          importExcelUrl: "ppgyJzzd/ppgyJzzd/importExcel",
          
        },
        dictOptions:{},
        superFieldList:[],
        visible:false,
        model1:{},
        validatorRules1: {
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        queryParam:{ppjzsbId:null},
      }
    },
    created() {
    this.getSuperFieldList();
    // if(this.$route.query.id === undefined || this.$route.query.id === ""){
    //   this.queryParam.ppjzsbId = ""
    //   // this.$set(this.queryParam,ppjzsbId,"")
    // }else{
    //   this.queryParam.ppjzsbId=this.$route.query.id
    //   // this.$set(this.queryParam,ppjzsbId,this.$route.query.id)
    // }
    // this.searchQuery()
    },
    mounted(){
      this.$nextTick(()=>{
        console.log('sadadsadsadsa')
        this.getQueryList(this.$route.query.id);
      })
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'ppjzsbId',text:'设备名称',dictCode:"ppgy_ppjzsb,sbmc,id"})
        fieldList.push({type:'int',value:'jzsj',text:'加注时间'})
        fieldList.push({type:'int',value:'xhsj',text:'循环加注的循环时间'})
        fieldList.push({type:'number',value:'yjpzbl',text:'药剂配置比例'})
        this.superFieldList = fieldList
      },
      handleInfo(record){
        console.log(record)
        this.visible = true
        this.model1 = Object.assign({}, record);
      },
      handleHistory(record){
        this.$router.push({path:"/ppgyjk/yckz/jzzdls",query:{znjzhistoryid:record.ppjzsbId}})
      },
      handleOk(){
        console.log(this.model1);
        this.model1.id = ''
        var d = {}
        // d.serialNo = this.model1.controlDeviceId
        // d.actoin='setMode'
        // d.data = {'volume':this.model1.fillingVolumeDay,'mixingTimeSpace':this.model1.mixingInterval,'mixingTimeLength':this.model1.mixingTime}
        // console.log(d);
        // httpAction('/PIData',d).then(r=>{
        //   if(res.code === 1){
        //     httpAction('/jzzdls/ppgyJzzdls/add',this.model1,'post').then((res)=>{
        //       if(res.success){
        //         this.$message.success(res.message);
        //         this.$emit('ok');
        //         this.visible = false
        //       }else{
        //         this.$message.warning(res.message);
        //       }
        //     })
        //   }
        // })
        httpAction('/jzzdls/ppgyJzzdls/add',this.model1,'post').then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.$emit('ok');
            this.visible = false
          }else{
            this.$message.warning(res.message);
          }
        })
      },
      handleCancel () {
        this.visible = false
      },
      getQueryList(id){
        console.log(id);
        this.queryParam.ppjzsbId = id
        
        setTimeout(() => {
          this.searchQuery()
        }, 100);
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>